/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  javafx.fxml.FXMLLoader
 *  javafx.scene.Node
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.BeanUtils
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.util.StringUtils
 */
package com.gys.controller;

import com.gys.GysApplication;
import com.gys.common.util.CacheUtil;
import com.gys.controller.LoginController;
import com.gys.controller.dataManger.TokenManger;
import com.gys.data.example.GetUserOutData;
import com.gys.spliteService.data.GetLoginOutData;
import com.gys.view.LoginView;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

public class BaseController {
    private static final Logger log = LoggerFactory.getLogger(BaseController.class);
    @Autowired
    private LoginController loginController;

    public GetUserOutData getLoginUser() {
        GetUserOutData loginUser = null;
        if (!StringUtils.isEmpty(TokenManger.xToken) && (loginUser = (GetUserOutData)CacheUtil.get(TokenManger.xToken)) == null) {
            CacheUtil.remove(TokenManger.xToken);
        }
        if (loginUser == null) {
            TokenManger.removeToken();
        }
        return loginUser;
    }

    public GetLoginOutData getSpliteLoginUser() {
        GetUserOutData loginUser = (GetUserOutData)CacheUtil.get("logInUser");
        GetLoginOutData getLoginOutData = new GetLoginOutData();
        BeanUtils.copyProperties(loginUser, getLoginOutData);
        return getLoginOutData;
    }

    public void logout() {
        this.loginController.init();
        GysApplication.showView(LoginView.class);
        if (!StringUtils.isEmpty(TokenManger.xToken)) {
            CacheUtil.remove(TokenManger.xToken);
        }
        TokenManger.removeToken();
    }

    public Alert createAlert(Alert.AlertType alertType, String title, String content) {
        Alert alert = new Alert(alertType);
        alert.setHeaderText(title);
        if (!StringUtils.isEmpty(content)) {
            alert.setContentText(content);
        }
        return alert;
    }

    public Node loadFxml(String fxmlUrl, Object controller) {
        try {
            FXMLLoader fxmlloader = new FXMLLoader(this.getClass().getResource(fxmlUrl));
            fxmlloader.setController(controller);
            return (Node)fxmlloader.load();
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void init() {
    }

    public double getContentWidth() {
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle maximumWindowBounds = graphicsEnvironment.getMaximumWindowBounds();
        return maximumWindowBounds.getWidth() - 225.0;
    }

    public double getContentHeight() {
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle maximumWindowBounds = graphicsEnvironment.getMaximumWindowBounds();
        return maximumWindowBounds.getHeight() - 150.0;
    }
}

